package com.efuture.vdrp.android.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class LoginServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("gbk");
		response.setCharacterEncoding("gbk");
		String name = request.getParameter("name");
		String pwd = request.getParameter("pwd");
		String beizhu = request.getParameter("qx").trim();
		//MySQL sql = new MySQL();
		WebApplicationContext webcontext = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
		MySQL sql =(MySQL)webcontext.getBean("MySQL");
	
		String str = sql.login(name, pwd, beizhu);
		sql.close();
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		pw.write(str);
		pw.flush();
		pw.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
